package icu.lookyousmileface.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author starrysky
 * @title: SwaggerConfiguration
 * @projectName Swagger2_Final
 * @description: 配置类
 * @date 2021/2/200:52
 */
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfiguration {

    /**
     * 配置Swagger的Docket的Bean实例
     *
     * @return new Docket
     */
    @Bean
    public Docket docket1(Environment environment) {
        /**
         * 设置swagger要显示的环境条件
         */
        Profiles profiles = Profiles.of("dev", "test");
        /**
         * 判断当前是否处于该环境
         */
        boolean status = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo1())
                .groupName("StarrySky")
                //设置swagger仅在选定的环境下显示
                .enable(status)
                .select()
                .apis(RequestHandlerSelectors.basePackage("icu.lookyousmileface.controller"))
                .paths(PathSelectors.ant("/**"))
                .build();
    }

    @Bean
    public Docket docket2(Environment environment) {
        Profiles profiles = Profiles.of("dev", "test");
        boolean status = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo2())
                .groupName("满天星")
                .enable(status)
                .select()
                .apis(RequestHandlerSelectors.basePackage("icu.lookyousmileface.controller"))
                .paths(PathSelectors.ant("/swagger/**"))
                .build();

    }

    /**
     * 配置Swagger信息apiInfo
     * 配置文档信息
     *
     * @return new ApiInfo
     */
    @Bean
    public ApiInfo apiInfo1() {
        Contact contact = new Contact("Starrysky", "https://www.cnblogs.com/SkystarX/", "1974952857@qq.com");
        return new ApiInfo(
                //标题
                "Blue-Sky的API文档",
                //m描述
                "即使夜再黑也会天亮！",
                //b版本
                "v1.0",
                //组织连接
                "https://www.cnblogs.com/SkystarX/",
                //联系人信息
                contact,
                //许可证
                "Apache 2.0 许可",
                //许可连接
                "http://www.apache.org/licenses/LICENSE-2.0",
                //扩展
                new CopyOnWriteArrayList<>());
    }

    @Bean
    public ApiInfo apiInfo2() {
        Contact contact = new Contact("ManTianXing", "https://www.cnblogs.com/SkystarX/", "1974952857@qq.com");
        return new ApiInfo(
                //标题
                "满天星的API文档",
                //m描述
                "夜即使在深，也会有天亮的一刻！",
                //b版本
                "v1.0",
                //组织连接
                "https://www.cnblogs.com/SkystarX/",
                //联系人信息
                contact,
                //许可证
                "Apache 2.0 许可",
                //许可连接
                "http://www.apache.org/licenses/LICENSE-2.0",
                //扩展
                new CopyOnWriteArrayList<>());
    }
}
